package com.app.service.impl;

import com.app.mapper.EquipMapper;
import com.app.model.EquipModel;
import com.app.service.EquipService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EquipServiceImpl implements EquipService {
    @Autowired
    private EquipMapper equipMapper;

    @Override
    public void update(EquipModel equipModel) {
        equipMapper.updateById(equipModel);
    }

    @Override
    public void insert(EquipModel equipModel) {
        equipMapper.insert(equipModel);
    }

    @Override
    public void delete(Integer id) {
        equipMapper.deleteById(id);
    }

    @Override
    public Page<EquipModel> selectCarList(Integer page, Integer limit, String name, Integer sortType) {
        Page<EquipModel> pages = new Page<>();
        pages.setCurrent(page);
        pages.setSize(limit);
        QueryWrapper<EquipModel> queryWrapper = new QueryWrapper<>();
        if (name != null && !name.equals("")) {
            queryWrapper.like("equip_number", name);
        }
        if (sortType==null || sortType==1){
            queryWrapper.orderByAsc("number").orderByDesc("create_time");
        }else {
            queryWrapper.orderByDesc("number").orderByDesc("create_time");
        }
        return equipMapper.selectPage(pages,queryWrapper);
    }
}
